package com.sxbbc.seller.util;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.sxbbc.common.core.entity.jz.BLogin;
import com.sxbbc.common.core.entity.jz.BMenus;

/**
 * 商家session
 * @author YQQ
 *
 */
public class BusinessSession {
	
	/**
	 * 商家对象
	 */
	public static final String BUSINESS_SESSION="BUSINESS_SESSION";
	
	/**
	 * 菜单对象
	 */
	public static final String MENU_LIST="MENU_LIST";
	
	/**
	 * 验证码
	 */
	public static final String VALIDATE_CODE="VALIDATE_CODE";
	
	/**
	 * 是否子菜单
	 */
	public static final String IS_CHILDREN="IS_CHILDREN";
	
	/***
	 * 登录人(店铺)ID
	 */
	public static final String BUSINESS_ID="BUSINESS_ID";
	
	
	/***
	 * 登录人账号
	 */
	public static final String USER_NAME="USER_NAME";
	
	/***
	 * 角色ID
	 */
	public static final String ROLE_ID="ROLE_ID";
	
	
	 /**
     * 菜单URL
     */
    public static final String MENU_URL = "session_menuUrl";

	/**
	 * 商家编码
	 */
	public static final String BUSINESS_CODE = "BUSINESS_CODE";

	/**
	 * 店铺id
	 */
	public static final String BID = "B_ID";

	public static void setBid(HttpServletRequest request,Integer bid){
		request.getSession().removeAttribute(BID);
		request.getSession().setAttribute(BID,bid);
	}

	public static Integer getBid(HttpServletRequest request){
		Integer bid = (Integer) request.getSession().getAttribute(BID);
		return bid;
	}

	/**
	 * session设置商家编码
	 * @param request
	 * @param businessCode
	 */
	public static void setBusinessCode(HttpServletRequest request,String businessCode){
		request.getSession().removeAttribute(BUSINESS_CODE);
		request.getSession().setAttribute(BUSINESS_CODE,businessCode);
	}

	/**
	 * session获取商家编码
	 * @param request
	 * @return
	 */
	public static String getBusinessCode(HttpServletRequest request){
		String businessCode = (String) request.getSession().getAttribute(BUSINESS_CODE);
		return businessCode;
	}
	
	
	/**
	 * 退出清除session
	 * @param request
	 */
	public static void exitSession(HttpServletRequest request){
		request.getSession().removeAttribute(BUSINESS_SESSION);
		request.getSession().removeAttribute(MENU_LIST);
		request.getSession().removeAttribute(VALIDATE_CODE);
		request.getSession().removeAttribute(IS_CHILDREN);
		request.getSession().removeAttribute(BUSINESS_ID);
		request.getSession().removeAttribute(USER_NAME);
		request.getSession().removeAttribute(ROLE_ID);
		request.getSession().removeAttribute(BUSINESS_CODE);
	}
	
	/**
	 * 角色ID设置session
	 * @param list
	 */
	public static void setRoleid(HttpServletRequest request ,Integer roleid){
		request.getSession().removeAttribute(ROLE_ID);
		request.getSession().setAttribute(ROLE_ID, roleid);
	}
	
	/**
	 * 角色ID对象获取session
	 * @param bBusiness
	 */
	public static Integer getRoleid(HttpServletRequest request){
		Integer roleid=(Integer) request.getSession().getAttribute(ROLE_ID);
		return roleid;
	}
	
	/**
	 * 登录人账号对象设置session
	 * @param list
	 */
	public static void setLoginName(HttpServletRequest request ,String username){
		request.getSession().removeAttribute(USER_NAME);
		request.getSession().setAttribute(USER_NAME, username);
	}
	
	/**
	 * 登录人账号对象获取session
	 * @param bBusiness
	 */
	public static String getLoginName(HttpServletRequest request){
		String loginname=(String) request.getSession().getAttribute(USER_NAME);
		return loginname;
	}
	
	/**
	 * 店铺ID对象设置session
	 * @param list
	 */
	public static void setLoginID(HttpServletRequest request ,Integer userid){
		request.getSession().removeAttribute(BUSINESS_ID);
		request.getSession().setAttribute(BUSINESS_ID, userid);
	}
	
	/**
	 * 店铺ID对象获取session
	 * @param bBusiness
	 */
	public static Integer getLoginID(HttpServletRequest request){
		Integer loginid=(Integer) request.getSession().getAttribute(BUSINESS_ID);
		return loginid;
	}
	

	/**
	 * 验证码对象设置session
	 * @param list
	 */
	public static void setValidCode(HttpServletRequest request ,String validcode){
		request.getSession().removeAttribute(VALIDATE_CODE);
		request.getSession().setAttribute(VALIDATE_CODE, validcode);
	}
	
	/**
	 * 验证码对象获取session
	 * @param bBusiness
	 */
	public static String getValidCode(HttpServletRequest request){
		String validcode=(String) request.getSession().getAttribute(VALIDATE_CODE);
		return validcode;
	}
	
	/**
	 * 菜单对象设置session
	 * @param list
	 */
	public static void setMenuList(HttpServletRequest request ,List<BMenus> list){
		request.getSession().removeAttribute(MENU_LIST);
		request.getSession().setAttribute(MENU_LIST, list);
	}
	
	/**
	 * 菜单对象获取session
	 * @param bBusiness
	 */
	public static List<BMenus> getMenuList(HttpServletRequest request){
		List<BMenus> list=(List<BMenus>) request.getSession().getAttribute(MENU_LIST);
		return list;
	}
	
	/**
	 * 店铺对象设置session
	 * @param bBusiness
	 */
	public static void setBLogin(HttpServletRequest request ,BLogin bLogin){
		request.getSession().removeAttribute(BUSINESS_SESSION);
		request.getSession().setAttribute(BUSINESS_SESSION, bLogin);
		request.getSession().setMaxInactiveInterval(60000000);//单位为秒
	}
	
	/**
	 * 店铺对象获取session
	 * @param bBusiness
	 */
	public static BLogin getBLogin(HttpServletRequest request){
		BLogin bLogin=(BLogin) request.getSession().getAttribute(BUSINESS_SESSION);
		return bLogin;
	}
	
	
	/**
	 * 店铺对象移除session
	 * @param bBusiness
	 */
	public static void removeBusiness(HttpServletRequest request){
		request.getSession().removeAttribute(BUSINESS_SESSION);
	}
	
	/**
     * 菜单URL设置session
     * @param request
     * @param list
     * @return void
     */
    public static void setMenuUrl(HttpServletRequest request, List<String> list) {
        request.getSession().removeAttribute(MENU_URL);
        request.getSession().setAttribute(MENU_URL, list);
    }

    /**
     *  菜单URL获取session
     * @param request
     * @return java.util.List<java.lang.String>
     */
    public static List<String> getMenuUrl(HttpServletRequest request) {
        @SuppressWarnings("unchecked")
        List<String> list = (List<String>) request.getSession().getAttribute(MENU_URL);
        return list;
    }
}
